package com.dmcb.trade.business.crawlers.article;

import com.dmcb.trade.business.constants.CrawlConstant;
import com.dmcb.trade.business.entities.Article;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Service;

/**
 * 凤凰资讯文章解析器
 * Created by Administrator on 2016/4/28.
 */
@Service
public class FengHuangParser extends BaseParser {

    /**
     * 网站URL网址
     *
     * @return 链接
     */
    @Override
    protected String url() {
        return CrawlConstant.FENGHUANG_URL;
    }

    /**
     * 获取标题选择器
     *
     * @return 标题选择器
     */
    @Override
    protected String titleSelect() {
        return "div.dl_cont_det_tit>h2,div.artical>h1,div.zw-word>h3.n-title,div.e_i_deta_LXT>h1,div.title>h2,div.ya_main_tit>h1,div.yc_tit>h1,div#artical>h1#artical_topic,div.acTxtTit>h1,span#thread_subject,div.titleLine-gY7DniPB>h1";
    }

    /**
     * 获取日期选择器
     *
     * @return 发布日期选择器
     */
    @Override
    protected String dateSelect() {
        return "div.e_i_deta_LXT>p,div.title>div>span,div.yamt_time>span,div.yc_tit>p>span,div#artical_sth>p.p_time>span.ss01,p.n-i-time";
    }

    /**
     * 获取正文内容选择器
     *
     * @return 正文内容选择器
     */
    @Override
    protected String bodySelect() {
        return "div.e_i_deta_LXD,div.article,div.ya_main_con,div#main_content,div.yc_con_txt,div.n-words";
    }

    /**
     * 获取封面选择器
     *
     * @return 封面选择器
     */
    @Override
    protected String coverSelect() {
        return "div.e_i_deta_LXD>p img[src],div.article>p img[src],div.ya_main_con>p>span img[src],div#main_content>p img[src],p.detailPic img[src],div.yc_con_txt>p img[src],div.n-words img[src]";
    }

    @Override
    protected void setAuthorName(Document doc, Article article) {
        Elements elements  = doc.select("div.yc_tit>p>a");
        if(elements.size()>2){
            article.setAuthorName(elements.get(1).text());
        }else{
            article.setAuthorName(doc.select(authorNameSelect()).text());
        }
    }

    @Override
    protected String authorNameSelect() {
        return "p.n-i-source";
    }

    @Override
    protected String platform() {
        return "凤凰网";
    }
}
